package com.inno.subject.domain.service.impl;

import com.inno.subject.domain.convert.SubjectTypeConverter;
import com.inno.subject.domain.entity.SubjectTypeBO;
import com.inno.subject.domain.service.SubjectTypeDomainService;
import com.inno.subject.domain.utils.CacheUtil;
import com.inno.subject.infra.basic.entity.PlannerSubjectType;
import com.inno.subject.infra.basic.service.PlannerSubjectTypeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
public class SubjectTypeDomainServiceImpl implements SubjectTypeDomainService {
    private final PlannerSubjectTypeService plannerSubjectTypeService;
    private final CacheUtil<SubjectTypeBO> cacheUtil;

    @Override
    public List<SubjectTypeBO> queryList() {
        String cacheKey = "subject_type_list";
        return cacheUtil.getSubjectType(cacheKey, SubjectTypeBO.class, (t) -> getTypeList());
    }

    private List<SubjectTypeBO> getTypeList() {
        List<PlannerSubjectType> entityList = this.plannerSubjectTypeService.queryList();
        return SubjectTypeConverter.INSTANCE.convertEntityListToBOList(entityList);
    }
}
